import matplotlib.pyplot as plt
import numpy as np

# Predictor variable names in SPSS order
variables = [
    "Human_Only", "Tactical_AI", "Strategic_AI", "Education",
    "Career_Length", "Cyber_Know_How", "FP_Know_How", "Risk_Aversion"
]

# Coefficients and SEs for DV1
B_DV1 = np.array([0.858, 1.434, 0.396, -0.007, -0.041, -0.203, 0.066, 0.555])
SE_DV1 = np.array([0.235, 0.240, 0.279, 0.049, 0.017, 0.100, 0.176, 0.197])

# Coefficients and SEs for DV2
B_DV2 = np.array([0.630, 1.000, 0.472, -0.057, -0.028, -0.311, 0.393, 1.740])
SE_DV2 = np.array([0.258, 0.250, 0.288, 0.047, 0.016, 0.097, 0.164, 0.196])

# Y positions
y_pos = np.arange(len(variables))

# Plot
plt.figure(figsize=(10, 6))

# Plot DV1
plt.errorbar(B_DV1, y_pos + 0.1, xerr=1.96 * SE_DV1, fmt='o', color='tab:blue', label='DV1')

# Plot DV2
plt.errorbar(B_DV2, y_pos - 0.1, xerr=1.96 * SE_DV2, fmt='s', color='tab:orange', label='DV2')

# Add vertical line at 0
plt.axvline(x=0, color='gray', linestyle='--')

# Labels and title
plt.yticks(y_pos, variables)
plt.xlabel("B Coefficient (with 95% CI)")
plt.title("Overlaid Forest Plot of Logistic Regression Coefficients")
plt.legend()

plt.tight_layout()
plt.grid(True, axis='x', linestyle=':')

# Save to file
plt.savefig("forest_overlay_dv1_dv2.png", dpi=300)
plt.show()
